package com.coocaa.app.gamecenter.pages.arsenal.view;

        import android.content.Context;
        import android.graphics.Canvas;
        import android.graphics.Color;
        import android.graphics.Paint;
        import android.graphics.Path;
        import android.graphics.Rect;
        import android.graphics.RectF;
        import android.util.AttributeSet;
        import android.view.View;

        import com.coocaa.x.framework.app.CoocaaApplication;
        import com.tianci.appstore.R;

/**
 * Created by xfk on 2015/11/5.
 */
public class polygonView extends View implements Runnable {
    // 声明Paint对象
    private Paint mPaint = null;
    private Context context;

    private View mGameView2 = null;

    public polygonView(Context context, AttributeSet attr){
        super(context,attr);
        this.context = context;
// 构建画笔对象
        mPaint = new Paint();

        mGameView2 = new View(context);
// 开启线程
        new Thread(this).start();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

// 设置画布为黑色背景
//        canvas.drawColor(Color.BLACK);

// 取消锯齿
        mPaint.setAntiAlias(true);

// 设置画笔风格为空心
        mPaint.setStyle(Paint.Style.STROKE);
        Path path1 = new Path();

/**
 * 这个多变形我也没试验它到底是怎么画 应该就是从起点 找点 一个点 一个点的连线
 */
            path1.moveTo(CoocaaApplication.Div(3), CoocaaApplication.Div(3)); // 此点为多边形的起点
            path1.lineTo(CoocaaApplication.Div(630), CoocaaApplication.Div(3));
            path1.lineTo(CoocaaApplication.Div(732), CoocaaApplication.Div(103));
            path1.lineTo(CoocaaApplication.Div(732), CoocaaApplication.Div(832));
            path1.lineTo(CoocaaApplication.Div(103), CoocaaApplication.Div(832));
            path1.lineTo(CoocaaApplication.Div(3), CoocaaApplication.Div(733));
// 使这些点构成封闭的多边形
            path1.close();

            mPaint.setColor(context.getResources().getColor(R.color.arsenal_preview_frame_color));
// 绘制这个多边形
            canvas.drawPath(path1, mPaint);
            mPaint.setColor(Color.RED);
// 设置画笔空心边框的宽度
            mPaint.setStrokeWidth(CoocaaApplication.Div(5));

    }

    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
// 使用postInvalidate可以直接在线程中更新界面
            postInvalidate();
            break;
        }

    }

}
